package com.etongwl.socketlibrary.library2;


/**
 * Created by jason on 16/6/27.
 * 消息队列管理
 */
public class MessageQueueManager {
    public static void manager(){
        ThreadCore threadCore=new ThreadCore(){
            @Override
            public void run() {
                super.run();
            }
        };
        threadCore.start();


        final HanderCore handerCore=new HanderCore(){
            @Override
            public void handleMessage(MessageCore msg) {
                super.handleMessage(msg);
                System.out.println("thread 000 handleMessage is run:"+msg.toString());

            }
        };

        Thread thread =new Thread(){
            @Override
            public void run() {
//                HanderCore handerCore=new HanderCore(){
//                    @Override
//                    public void handleMessage(MessageCore msg) {
//                        super.handleMessage(msg);
//                        System.out.println("handleMessage is run:"+msg.toString());
//
//                    }
//                };
                System.out.println("线程运行");

                int m=100;
                long t=System.currentTimeMillis();
                for (int i =0;i<m;i++){
                    System.out.println("thread handleMessage for is run:"+i);
                    MessageCore msg=handerCore.obtainMessage();
                    msg.setWhat((i+1));
                    msg.setMsg("send msg content is "+i);
                    msg.sendToTarget();
                }

//                MessageCore msg=handerCore.obtainMessage();
//                msg.setWhat(-1);
//                msg.setMsg("send msg quit ");
//                msg.sendToTarget();
            }
        };

        thread.start();



        Thread thread1 =new Thread(){
            @Override
            public void run() {
                System.out.println("线程1运行");
//                HanderCore handerCore=new HanderCore(){
//                    @Override
//                    public void handleMessage(MessageCore msg) {
//                        super.handleMessage(msg);
//                        System.out.println("thread 1 handleMessage is run:"+msg.toString());
//
//                    }
//                };
                int m=100;
                for (int i =0;i<m;i++){
                    System.out.println("thread 1 handleMessage for is run:"+i);
                    MessageCore msg=handerCore.obtainMessage();
                    msg.setWhat((i+1));
                    msg.setMsg("thread 1 msg content is "+i);
                    msg.sendToTarget();
                }

//                MessageCore msg=handerCore.obtainMessage();
//                msg.setWhat(-1);
//                msg.setMsg("thread 1 send msg quit ");
//                msg.sendToTarget();

            }
        };

        thread1.start();
    }

}
